using System;
using System.Collections;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Connection;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;

namespace Me.Prettyprint.Cassandra.Model.Thrift
{
	public class ThriftFactory
	{
		public static ColumnPath CreateColumnPath<N>(string columnFamilyName, N columnName, Serializer<N> nameSerializer)
        {
            return CreateColumnPath<N>(columnFamilyName, nameSerializer.ToBytes(columnName));
        }
        private static ColumnPath CreateColumnPath<N>(string columnFamilyName, byte[] columnName)
        {
            if (columnFamilyName == null)
            {
                throw new NullReferenceException("ColumnFamilyName cannot be null");
            }
            ColumnPath columnPath = new ColumnPath();
            columnPath.Column_family = columnFamilyName;
            if (columnName != null)
            {
                columnPath.Column = columnName;
            }
            return columnPath;
        }
        public static ColumnPath CreateColumnPath<N>(string columnFamilyName)
        {
            return CreateColumnPath<N>(columnFamilyName, null);
        }
        public static ColumnPath CreateSuperColumnPath<SN,N>(string columnFamilyName,
            SN superColumnName, N columnName, Serializer<SN> superNameSerializer,
            Serializer<N> nameSerializer)
        {
            if (columnFamilyName == null || superColumnName == null || superNameSerializer == null || nameSerializer == null)
            {
                throw new NullReferenceException("ColumnFamilyName, SuperColumnName, SuperNameSerializer and NameSerializer cannot be null");
            }
            ColumnPath columnPath = CreateColumnPath<N>(columnFamilyName, nameSerializer.ToBytes(columnName));
            columnPath.Super_column = superNameSerializer.ToBytes(superColumnName);
            return columnPath;
        }
        public static ColumnPath CreateSuperColumnPath<SN>(string columnFamilyName,
            SN superColumnName, Serializer<SN> superNameSerializer)
        {
            if (columnFamilyName == null || superNameSerializer == null)
            {
                throw new NullReferenceException("ColumnFamilyName, and SuperNameSerializer cannot be null");
            }
            ColumnPath columnPath = CreateColumnPath<SN>(columnFamilyName, null);
            if (superColumnName != null)
            {
                columnPath.Super_column = superNameSerializer.ToBytes(superColumnName);
            }
            return columnPath;
        }
        public static CounterColumn CreateCounterColumn(string name, long value)
        {
            CounterColumn cc = new CounterColumn();
            cc.Name = StringSerializer.Instance.ToBytes(name);
            cc.Value = value;
            return cc;
        }
        public static CounterColumn CreateCounterColumn<N>(N name, long value, Serializer<N> ns)
        {
            CounterColumn cc = new CounterColumn();
            cc.Name = ns.ToBytes(name);
            cc.Value = value;
            return cc;
        }
	}
}